package net.wanho.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.wanho.po.ProductType;
import net.wanho.service.ProductTypeService;
import net.wanho.mapper.ProductTypeMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author 王洋
* @description 针对表【product_type(商品分类表)】的数据库操作Service实现
* @createDate 2024-09-03 17:43:36
*/
@Service
@RequiredArgsConstructor
public class ProductTypeServiceImpl extends ServiceImpl<ProductTypeMapper, ProductType>
    implements ProductTypeService{
    private final ProductTypeMapper productTypeMapper;

    @Override
    public List<ProductType> typeList() {
        List<ProductType> productTypeList = this.list();
        List<ProductType> productTypeList1 = productTypeList.stream()
                .filter(item -> item.getParentId() == 0)
                .map(item-> {
                    List<ProductType> childProductCategory = productTypeList.stream()
                            .filter(item1 -> item1.getParentId().equals(item.getTypeId()))
                            .collect(Collectors.toList());
                    item.setChildProductCategory(childProductCategory);
                    return item;
                }).collect(Collectors.toList());
        return productTypeList1;
    }

    @Override
    public boolean verifyTypeCode(String typeCode) {
       ProductType productType = productTypeMapper.verifyTypeCode(typeCode);
       if(ObjectUtils.isEmpty(productType)){
           return true;
       }
       else {
           return false;
       }
       }

}




